import os
from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import (DeclareLaunchArgument, GroupAction,
                            IncludeLaunchDescription, SetEnvironmentVariable)
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.actions import DeclareLaunchArgument
from launch.substitutions import LaunchConfiguration
import launch_ros.actions

#def launch(launch_descriptor, argv):
def generate_launch_description():
#    rplidar_dir = get_package_share_directory('lidar_ros2')
#    rplidar_launch_dir = os.path.join(rplidar_dir, 'launch')
    cam_dir = os.path.join(get_package_share_directory('mipi_cam'), 'launch')
    codec_dir = os.path.join(get_package_share_directory('hobot_codec'), 'launch')
    bringup_dir = get_package_share_directory('turn_on_wheeltec_robot')
    launch_dir = os.path.join(bringup_dir, 'launch')
    wheeltec_robot = IncludeLaunchDescription(
            PythonLaunchDescriptionSource(os.path.join(launch_dir, 'turn_on_wheeltec_robot.launch.py')),
    )
    rplidar_ros = IncludeLaunchDescription(
            PythonLaunchDescriptionSource(os.path.join(launch_dir, 'wheeltec_lidar.launch.py')),
    )
    camera = IncludeLaunchDescription(
            #PythonLaunchDescriptionSource(os.path.join(cam_dir, 'mipi_cam_640x480_nv12_hbmem.launch.py')),
            PythonLaunchDescriptionSource(os.path.join(cam_dir, 'mipi_cam_1920x1080_nv12_hbmem.launch.py')),
    )
    codec = IncludeLaunchDescription(
            PythonLaunchDescriptionSource(os.path.join(codec_dir, 'hobot_codec_encode.launch.py')),
            launch_arguments={
                'codec_in_mode': 'shared_mem',
                #'codec_out_mode': 'shared_mem',
                'codec_out_format': 'jpeg',
                'codec_pub_topic': '/image_raw/compressed'
            }.items(),
    )
    return LaunchDescription([
        rplidar_ros,wheeltec_robot,camera,codec,]
    )

